package com.hungryinlindholmen;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Receives a request from edit.jsp and creates a newDb object depending on what
 * parameters are received. The parameter addDone is set to null. Forwards to
 * owner.jsp.
 * 
 * @author Ludvig Gee
 */

@WebServlet("/NewServlet")
public class NewServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {

	String dishAla = request.getParameter("dishAla");
	String descriptionAla = request.getParameter("descriptionAla");
	String priceAla = request.getParameter("priceAla");
	String typeAla = request.getParameter("typeAla");

	String dateLunch = request.getParameter("dateLunch");
	String dishLunch = request.getParameter("dishLunch");
	String DescriptionLunch = request.getParameter("DescriptionLunch");
	String priceLunch = request.getParameter("priceLunch");
	String typeLunch = request.getParameter("typeLunch");

	String restID = (String) request.getSession().getAttribute("restID");

	request.setAttribute("addDone", null);

	NewDb add = new NewDb(restID);
	if (dateLunch != null) {

	    add.NewLunch(restID, dateLunch, dishLunch, DescriptionLunch,
		    priceLunch, typeLunch);
	    request.setAttribute("restID", add.getRestID());
	    request.setAttribute("addDone", add.getAddDone());
	    RequestDispatcher dispatcher = request
		    .getRequestDispatcher("owner.jsp");
	    dispatcher.forward(request, response);
	} else {
	    add.NewAla(restID, dishAla, descriptionAla, priceAla, typeAla);
	    request.setAttribute("restID", add.getRestID());
	    request.setAttribute("addDone", add.getAddDone());
	    RequestDispatcher dispatcher = request
		    .getRequestDispatcher("owner.jsp");
	    dispatcher.forward(request, response);
	}

    }

}
